@extends('shared.adminBase')
@section('title','兑换记录')
@section('content')
    <section class="content-header">
        <h1>兑换记录</h1>
        <ol class="breadcrumb">
            <li><a href="{{URL::action('AdminController@innerIndex')}}"><i class="fa fa-home"></i> 首页</a></li>
            <li class="active">兑换记录</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box">
                    <div class="box-header"></div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                            <form id="form1" action="{{URL::action('GameController@getExchangeRecordList')}}"
                                  method="get">
                                <input type="hidden" name="page" value="{{$pagerSet->currentPage()}}">
                                <input type="hidden" name="export" value="false">
                                <div class="row" style="margin-left: 5px;">
                                    <label>订单号：<input class="form-control" name="id"
                                                      value="{{$form->id}}"></label>
                                    <label>商品名称：<input class="form-control" name="productName"
                                                       value="{{$form->productName}}"></label>
                                    <label>玩家ID：<input class="form-control" name="userID"
                                                       value="{{$form->userID}}"></label>
                                    <label>状态：
                                        <select name="status">
                                            <option value="">全部</option>
                                            @foreach(App\Framework\Enum\ExchangeRecordStatusEnum::$dataMap as $k=>$v)
                                                @if($k==$form->status)
                                                    <option value="{{$k}}" selected="selected">{{$v}}</option>
                                                @else
                                                    <option value="{{$k}}">{{$v}}</option>
                                                @endif
                                            @endforeach
                                        </select>
                                    </label>
                                    <label>订单时间:</label>
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" name="startDate" value="{{$form->startDate}}"
                                               class="form-control pull-right" id="startDate">
                                    </div>
                                    <span>-</span>
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" name="endDate" value="{{$form->endDate}}"
                                               class="form-control pull-right" id="endDate">
                                    </div>
                                    <button type="submit" class="btn btn-primary">查询</button>
                                    <button type="button" onclick="clearForm('form1');" class="btn btn-primary">清空
                                    </button>
                                </div>
                            </form>
                            <br/>
                            <div class="row col-sm-12">
                                <button class="btn btn-default"
                                        onclick="batchSetStatus('{{App\Framework\Enum\ExchangeRecordStatusEnum::SUCCESS}}');">
                                    兑换成功
                                </button>
                                <button class="btn btn-default"
                                        onclick="batchSetStatus('{{App\Framework\Enum\ExchangeRecordStatusEnum::SENDED}}');">
                                    已发货
                                </button>
                                <button class="btn btn-default"
                                        onclick="batchSetStatus('{{App\Framework\Enum\ExchangeRecordStatusEnum::RECEIVED}}');">
                                    已收货
                                </button>
                            </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <table id="example1" class="table table-bordered table-striped dataTable"
                                           role="grid" aria-describedby="example1_info">
                                        <thead>
                                        <tr role="row">
                                            <th><label><input type="checkbox" id="selectAll" onclick="selectAll(this);">全选</label>
                                            </th>
                                            <th>订单号</th>
                                            <th>商品名称</th>
                                            <th>数量</th>
                                            <th>用户ID</th>
                                            <th>手机号</th>
                                            <th>订单时间</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($pagerSet as $item)
                                            <tr role="row" class="odd">
                                                <td><input type="checkbox" name="recordID"
                                                           value="{{$item->exchange_record_id}}"></td>
                                                <td>{{$item->exchange_record_id}}</td>
                                                <td>{{$item->product_name}}</td>
                                                <td>{{$item->quantity}}</td>
                                                <td>{{$item->user_id}}</td>
                                                <td>{{$item->telephone}}</td>
                                                <td>{{$item->create_date}}</td>
                                                <td>{{App\Framework\Enum\ExchangeRecordStatusEnum::getName($item->status)}}</td>
                                                <td><a href="{{URL::action('GameController@getExchangeRecordDetail',['id'=>$item->exchange_record_id])}}"
                                                            class="btn-xs btn-default">查看</a></td>
                                            </tr>
                                        @endforeach
                                    </table>
                                    <button class="btn btn-default"
                                            onclick="exportData();">
                                        导出Excel
                                    </button>
                                </div>
                            </div>
                            <div class="row">
                                @include('shared.tablePaginate')
                            </div>
                            </form>
                        </div>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@endsection


<script type="text/javascript">

    function selectAll(obj) {

        if ($(obj).is(":checked")) {
            $("[name='recordID']").prop('checked', true);
        } else {
            $("[name='recordID']").prop('checked', false);
        }
    }

    function batchSetStatus(status) {
        var recordIds = $("input[name='recordID']:checked").serialize();
        if (recordIds.length <= 0) {
            alert('请选择需要修改的记录');
            return false;
        }

        if (!confirm("确定要修改选中的记录状态吗？")) {
            return false;
        }

        $.post('{{URL::action('GameController@setExchangeRecordStatus')}}', {
            'recordID': recordIds,
            'status':status,
            '_token': '{{csrf_token()}}'
        }, function (result) {
            if (result.success) {
                window.location.reload();
            } else {
                alert(result.info);
            }
        });
    }

    function exportData() {
        $('[name="export"]').val('true');
        $('#form1').submit();
    }

</script>
